﻿using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.Web;
using System.Web.Http;

namespace Seed.IoC
{
    public abstract class MefHttpApplication : HttpApplication
    {
        public void Application_Start()
        {
            var catalog = CreateCatalog();
            var container = new CompositionContainer(catalog);

            ServiceLocator.SetServiceLocatorProvider(() => new MefServiceLocator(container));
            //ControllerBuilder.Current.SetControllerFactory(new MefControllerFactory(container));
            GlobalConfiguration.Configuration.DependencyResolver = new MefDependencyResolver(container);

            OnApplicationStarted();
        }

        protected virtual void OnApplicationStarted() { }

        protected abstract ComposablePartCatalog CreateCatalog();
    }
}